<?php
    header("Content-type:text/html;charset=utf-8");
    if ($_POST) {
        include '../../api/config.php';
        include './comm.php';
        //数据库配置文件
        $json = $_POST["data"];
        $data = json_decode($json);
        $id = $data->head;
        
        if ($id == '1012') {
            $ids = $data->ids;
            $sql3 = "DELETE FROM msg WHERE id = '{$ids}'";
            //查询系统消息
            if (flag($data)) {
                $stmt3 = $conn->query($sql3);
                $stmt3->execute();
                $result3 = $stmt3->setFetchMode(PDO::FETCH_ASSOC);
                echo get_msg('200','操作成功~',false,false);
            } else {
                echo get_msg('500','权限不足~','../index.html',false);
            }
        }
        //新建消息
        if ($id == '1011') {
            $conts = $data->conts;
            $url = $data->url;
            $flag = $data->flag;
            $timer = $data->timer;
            $sql5 = "INSERT INTO msg(conts,url,flag,timer) VALUES('{$conts}','{$url}','{$flag}','{$timer}')";
            //查询系统消息
            if (flag($data)) {
                $stmt5 = $conn->prepare($sql5);
                $stmt5->execute();
                $result5 = $stmt5->setFetchMode(PDO::FETCH_ASSOC);
                echo get_msg('200','操作成功~',false,false);
            } else {
                echo get_msg('500','权限不足~','../index.html',false);
            }
        }
        //新建消息
        if ($id == '1010') {
            $conts = $data->conts;
            $url = $data->url;
            $flag = $data->flag;
            $ids = $data->ids;
            $timer = $data->timer;
            $sql1 = "UPDATE msg SET conts='{$conts}',url='{$url}',flag='{$flag}',timer='{$timer}' WHERE id='{$ids}'";
            //查询系统消息
            if (flag($data)) {
                $stmt1 = $conn->query($sql1);
                $stmt1->execute();
                $result1 = $stmt1->setFetchMode(PDO::FETCH_ASSOC);
                echo get_msg('200','操作成功~',false,false);
            } else {
                echo get_msg('500','权限不足~','../index.html',false);
            }
        }
        //更新消息
        // 输出内容
        if ($id == '1009') {
            $sql1 = "SELECT * FROM msg";
            if (flag($data)) {
                $arr1 = array();
                $arr1['data'] = array();
                $stmt1 = $conn->query($sql1);
                $stmt1->execute();
                $result1 = $stmt1->setFetchMode(PDO::FETCH_ASSOC);
                $arr1['data'] = $stmt1->fetchAll();
                if ($result1) {
                    echo get_msg('200','操作成功~',false,$arr1['data']);
                } else {
                    $arr1['code'] = '400';
                    $arr1['msg'] = '数据异常~';
                    $data = json_encode($arr1);
                    echo $data;
                }
            } else {
                echo get_msg('500','权限不足~','../index.html',false);
            }
        }
        // 输出内容
        $conn = null;
    } else {
        echo "<script>\r\n    window.location.href = '../../';\r\n    </script>";
    }